package com.geekhole.demo.app.user;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

import static com.geekhole.demo.app.TimeUtil.sleep;

@Service
public class UserApplication {

    public User getByUserId(Long userId){
        sleep(20);
        User user = createUser(userId);
        return user;
    }

    private User createUser(Long userId) {
        User user = new User();
        user.setId(userId);
        user.setName("普通用户-" + userId);
        return user;
    }

    public List<User> getByUserIds(List<Long> userIds){
        sleep(50);
        return userIds.stream()
                .map(this::createUser)
                .collect(Collectors.toList());
    }
}
